package com.mofang.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.mofang.R;
import com.mofang.utils.ListHeightUtils;

public class NewHouseAdapter extends BaseAdapter {

	private ListView new_house_list;
	private LayoutInflater mInflater;
	Context context;
	int count = 10;

	public NewHouseAdapter(Context context) {
		// TODO Auto-generated constructor stub
		this.mInflater = LayoutInflater.from(context);
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return count;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Holder myHolder;
		if (convertView == null) {
			myHolder = new Holder();
			convertView = mInflater.inflate(
					R.layout.activity_main_source_list_item, null);
			convertView.setTag(myHolder);
		} else {
			myHolder = (Holder) convertView.getTag();
		}
		// myHolder.news_title.setText(list.get(position).get("news_title").toString());
		// myHolder.news_content.setText(list.get(position).get("news_content").toString());
		// myHolder.news_time.setText(list.get(position).get("news_time").toString());
		// myHolder.attachment.setImageResource((Integer)(list.get(position).get("attachment")));
		return convertView;
	}

	class Holder {
		ImageView attachment;
		TextView news_title;
		TextView news_content;
		TextView news_time;
	}

	// private void setView(LinearLayout parentView) {
	// parentView.removeAllViews();
	// for (int i = 0; i < 10; i++) {
	// View view = mInflater.inflate(
	// R.layout.activity_main_source_list_item, null);
	// parentView.addView(view);
	// }
	// }

	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
		ListHeightUtils.setListViewHeightBasedOnChildren(new_house_list);
	}
}
